/**
 * related to listCellTemplate.ui
 * 
 * @Author : chenglm
 * @Timestamp : 2016-07-13
 */
var page = sm("do_Page");
var nf = sm("do_Notification");
var button1 = ui("do_Button_1");
var button2 = ui("do_Button_2");
var button3 = ui("do_Button_3");
var root = ui("$");//$是这个ui文件根节点组件的通配符，如果指定组件的id，也可以用id来获取对象
var openHelper = require("helper/open");

root.setMapping({
	"do_Button_1.tag" : "id",
	"do_Button_2.tag" : "isDefault"
});

root.on("dataRefreshed", function(){
	var isDefault = button2.tag;
	if (isDefault == 1) {
		button1.text = "默认地址";
	}
});

//设置默认地址
button1.on("touch",function(){
	var isDefault = button2.tag;
	if (isDefault == 2) {
		page.fire("setDefault", button1.tag);
	}
});

//编辑
button2.on("touch",function(){
	openHelper.open("source://view/user/userAddress/edit.ui",button1.tag);
});

//删除
button3.on("touch",function(){
	nf.confirm({text:"是否确认删除?",title:"提示",button1text:"确定",button2text:"取消"},function(datacall,e){
		if(datacall == 1){
			page.fire("remove", button1.tag);
		}
	});
});